package com.bnz.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bnz.pojo.PageResult;
import com.bnz.pojo.R;
import com.bnz.pojo.Student;
import com.bnz.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@RestController
@RequestMapping("student")
public class StudentController {

	@Reference
	private StudentService studentService;

	@GetMapping("list")
	public R list(){

		List<Student> studentList=studentService.findAll();

		return R.ok().data("list",studentList);

	}
	@GetMapping("findByPage/{page}/{pageSize}")
	public R findByPage(@PathVariable Integer page,@PathVariable Integer pageSize){

		PageResult<Student> pr=studentService.findByPage(page,pageSize);

		return R.ok().data("pr",pr);
	}
	@PostMapping("search/{page}/{pageSize}")
	public R search(@PathVariable Integer page,@PathVariable Integer pageSize,@RequestBody Student student){
		PageResult<Student> pr=studentService.search(page,pageSize,student);

		return R.ok().data("pr",pr);
	}

	@PostMapping("add")
	public R add(@RequestBody Student student){

		studentService.add(student);
		return R.ok().message("添加学生成功");
	}

	@PostMapping("update")
	public R update(@RequestBody Student student){
		studentService.update(student);

		return R.ok().message("修改学生成功");
	}

	@DeleteMapping("delete/{sids}")
	public R delete(@PathVariable String[] sids){
		studentService.delete(sids);
		return R.ok().message("删除成功");
	}


}
